﻿@model Model.SysViewGroup
@{
    ViewBag.Title = "编辑推送组";
    Layout = "~/Views/Shared/_Main.cshtml";
}
@section Head{
    <style>
        .p2, .bigData
        {
            display: none;
        }
    </style>
    <script type="text/javascript">
        var UrlArray = $.getUrlArray();
        var dbName = UrlArray["dbName"];
        var systemID = UrlArray["systemID"];
        var DBType = UrlArray["DBType"];
        $(function () {
            if (UrlArray["DBType"] == "2") {
                $(".bigData").show();
            }
            page_Init();
        });
        function page_Init() {
            if ('@Model.ID' != "") {
                optsCB.url = "/SystemConfiguration/GetCallBackConfigList?groupID=" + '@Model.ID' + "&dbName=" + encodeURI(dbName);
                $("#DataGridCB").dg(optsCB);
            }
        }
        function btnBack_Click() {
            var url = "/EtlTarget/EtlTargetViewConfig?systemID=" + systemID + "&dbName=" + encodeURI(dbName);
            if (DBType == "2")
                url += "&DBType=" + DBType;
            window.location.href = url;
        }
        var pNum = 1;
        function AddPara(k, v) {
            $(".paras").append("<div class='ph" + pNum + "'>参数名 <input type='text' value='" + k + "' class='txtPara' style='width: 135px;' /> 参数值 <input type='text' value='" + v + "' class='txtParaValue' style='width: 155px;' /> <input type='button' value='删除' onclick='DelPara(" + pNum + ");' class='button' /></div>");
            pNum++;
        }
        function DelPara(v) {
            $(".ph" + v).remove();
        }
        function GetCallBackType(v) {
            if (v == 1) {
                $(".p1").show();
                $(".p2").hide();
            } else {
                $(".p2").show();
                $(".p1").hide();
            }
        }
        //----------事件 END----------------
        //----------Add CB begin---------------- 
        var retCBData = new Array();
        var optsCB = {
            height: 380,
            rows: 100,
            idField: "GUID",
            para: { systemID: systemID, dbName: encodeURI(dbName) },
            checkbox: true,
            columns: [
                    { field: 'CallBackType', title: '回调类型', width: 45, formatter: function (value, rowData, rowIndex) {
                        if (value == 1)
                            return "存储过程";
                        else
                            return "HTTP回调";
                    }
                    },
                    { field: 'CallBackName', title: '回调名称', width: 45 },
                    { field: 'GUID', title: '操作', width: 10, align: 'center',
                        formatter: function (value, rowData, rowIndex) {
                            var add = true; ;
                            for (var j = 0; j < retCBData.length; j++) {
                                if (retCBData[j].GUID == rowData.GUID) {
                                    add = false;
                                }
                            }
                            if (add) {
                                retCBData.push(rowData);
                            }
                            var acCB = "<select onchange='CBAction(this.options.selectedIndex," + rowIndex + ")' ><option value=''>-请选择-</option>";
                            return acCB + "<option >修改</option><option >删除</option></select>"
                        }
                    }
            ]
        };

        function CBAction(i, v) {
            if (i == 1)
                AddCB(v);
            else
                removeCB(v);
            $("#DataGridCB").dg(optsCB);
        }
        function AddCB(v) {
            showModalMany('editCB', '/SystemConfiguration/AddCallBack?id=' + v + '&dbType=1', '610', '205', AddCBInfo);
        }
        function AddCBInfo(v) {
            if (!v["GUID"]) {
                v["GUID"] = retCBData.length;
                retCBData.push(v);
            } else {
                retCBData[v["GUID"]] = v;
            }
            var data = { "total": 0, "rows": retCBData };
            optsCB["data"] = data;
            $("#DataGridCB").dg(optsCB);
        }
        function DelCB() {
            if (confirm("确定要删除吗？")) {
                var j = 1;
                $('#DataGridCB').find(":checkbox").each(function (i, d) {
                    if (i == 0)
                        return;
                    if (d.checked) {
                        retCBData.removeAt(i - j);
                        j++;
                    }
                });
                var data = { "total": 1, "rows": retCBData };
                optsCB["data"] = data;
                $("#DataGridCB").dg(optsCB);
            }
        }
        function removeCB(i) {
            if (confirm("确定要删除吗？")) {
                retCBData.removeAt(i);
                var data = { "total": 0, "rows": retCBData };
                optsCB["data"] = data;
                $("#DataGridCB").dg(optsCB);
            }
        }
        //----------Add CB end---------------- 
        //----------提交数据 ----------------
        function submitForm() {
            if ($.trim($("#txtGroupName").val()) == "") {
                alert("推送组名不能为空！");
                return;
            }
            if ($.trim(systemID) == "") {
                alert("对接系统信息错误！");
                return;
            }
            var postData = jv.GetDivArray($(".table_bg"), 3)
            postData["SysID"] = systemID;
            $.post("/ViewGroup/Update?dbName=" + encodeURI(dbName), { query: $.toJSON(postData), paras: $.toJSON(retCBData) }, function (result) {
                if (result.Success == true) {
                    alert(result.Message);
                    btnBack_Click();
                }
                else {
                    alert(result.Message);
                }
            })
        }
        //----------提交数据 END----------------
    </script>
}
<div style="margin: 5px;">
    <form id="ff" method="post">
    <table class="listTitle">
        <tr>
            <td width="15">
                <img src="/images/filesave.png" />
            </td>
            <td width="300">
                编辑对接系统推送组信息
            </td>
            <td align="right">
                <input id="btnSubmit" type="button" class="button" value="保存" onclick="submitForm()" />
                <input id="btnBack" type="button" class="button" value="返回" onclick="btnBack_Click()" />
            </td>
        </tr>
    </table>
    <table class="table_bg" style="width: 100%;" cellpadding="0" cellspacing="0">
        <tr>
            <td style="text-align: right; width: 100px;">
                <span class="red">*</span>推送组名：
            </td>
            <td>
                <input type="hidden" id="hddID" name="ID" value="@Model.ID" />
                <input type="text" id="txtGroupName" name="GroupName" value="@Model.GroupName" style="width:380px" />
            </td>
        </tr>
        <tr class="bigData">
            <td style="text-align: right;">
                并发量：
            </td>
            <td>
                <input type="text" id="txtConcurrentNum" name="GroupName" maxlength="8" value="@Model.ConcurrentNum" style="width:100px" onkeyup="this.value=checkNum(this.value)" />
            </td>
        </tr>
        <tr>
            <td style="text-align: right;" valign="top">
                描述：
            </td>
            <td style="padding-top: 2px; padding-bottom: 2px;">
                <textarea id="txtDescription" name="Description" rows='3' style="width: 380px">@Model.Description</textarea>
            </td>
        </tr>
    </table>
    <table class="listTitle">
        <tr>
            <td width="15">
                <img src="/images/edit.png" />
            </td>
            <td width="300">
                回调配置
            </td>
            <td align="right">
                <input type="button" value="添加" onclick="AddCB('');" class="button" />
                <input type="button" value="删除" onclick="DelCB();" class="button" />
            </td>
        </tr>
    </table>
    <table id="DataGridCB" class="pagTable" cellpadding="0" cellspacing="0">
    </table>
    </form>
</div>
